import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QTextEdit


class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        # 创建两个按钮
        self.btn1 = QPushButton("按钮1", self)
        self.btn2 = QPushButton("按钮2", self)
        self.btclean = QPushButton("清空", self)

        # 连接按钮的点击信号到对应的槽函数
        self.btn1.clicked.connect(self.btn1_clicked)
        self.btn2.clicked.connect(self.btn2_clicked)
        self.btclean.clicked.connect(self.btclean_clicked)

        # 创建用于输出日志的文本框
        self.log_textedit = QTextEdit(self)
        self.log_textedit.setReadOnly(True)

        layout = QVBoxLayout()
        layout.addWidget(self.btn1)
        layout.addWidget(self.btn2)
        layout.addWidget(self.log_textedit)
        layout.addWidget(self.btclean)
        self.setLayout(layout)

        self.setGeometry(300, 300, 300, 250)
        self.show()

    def btn1_clicked(self):
        self.log_textedit.append("按钮1被点击了")

    def btn2_clicked(self):
        self.log_textedit.append("按钮2被点击了")

    def btclean_clicked(self):
        self.log_textedit.clear()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())
